<?php

use yii\helpers\Html;
use common\components\ActiveForm;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $model common\models\links */
/* @var $form yii\widgets\ActiveForm */
?>
<hr/>
<div class="links-form">

    <?php $form = ActiveForm::begin([
		'options' => [
			'class' => 'form-horizontal',
			'enctype' => 'multipart/form-data'
		],
		'fieldConfig' => [
			'template' => "{label}\n<div class=\"col-xs-5\">{input}</div>\n{hint}\n{error}",
		]
	]); ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => 40])->label(null, [
		'class' => 'col-sm-2 control-label'
	]) ?>

    <?= $form->field($model, 'url')->textInput(['maxlength' => 100])->label(null, [
		'class' => 'col-sm-2 control-label'
	]) ?>

    <?= $form->field($model, 'image')->fileInput()->label(null, [
		'class' => 'col-sm-2 control-label'
	]) ?>

	<?php if($model->image): ?>
		<?= Html::activeHiddenInput($model, 'image') ?>
		<div class="col-xs-offset-2" style="margin-bottom: 5px">
			<span class="word-btn"></span>
			<?= Html::img('@web/' . $model->image, ['width' => 50, 'height' => 50]) ?>
		</div>
	<?php endif ?>

    <?= $form->field($model, 'sort')->textInput(['maxlength' => 8])->label(null, [
		'class' => 'col-sm-2 control-label'
	]) ?>

    <div class="form-group">
		<div class="col-xs-2"></div>
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', '新增链接') : Yii::t('app', '编辑链接'), ['class' => $model->isNewRecord ? 'btn btn-success word-btn' : 'btn btn-primary word-btn']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>

<script>
	<?php $this->beginBlock('js_end') ?>

	$(function(){
		highlight_subnav("<?= Url::to(['links/index']) ?>");
	});

	<?php $this->endBlock() ?>
</script>
<?php $this->registerJs($this->blocks['js_end'], \yii\web\View::POS_END); ?>
